<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>24.isPrototypeOf检测继承关系</title>
</head>

<body>

</body>
<script>
  // 使用 isPrototypeOf 判断一个对象是否在另一个对象的原型链中，下面是原理分析
  // 原理分析
  const a = {};
  const b = {
    __proto__: a
  };
  const c = {
    __proto__: b
  };
  console.log(a.isPrototypeOf(b)); //true
  console.log(a.isPrototypeOf(c)); //true    
  console.log(c.isPrototypeOf(b)); //false
  //下面在使用 class 语法中使用
  class Common { }
  class User extends Common { }
  class Admin extends User { }
  let hd = new Admin();

  console.log(Admin.prototype.isPrototypeOf(hd)); //true    
  console.log(User.prototype.isPrototypeOf(hd)); //false
  console.log(Common.prototype.isPrototypeOf(hd)); //true
</script>

</html>